//
//  UIButton+EX.swift
//  weibo1
//
//  Created by 李进 on 15/10/16.
//  Copyright © 2015年 李进. All rights reserved.
//

import UIKit

extension UIButton{
    
    /// 便利构造函数
    ///
    /// - parameter imageName:     按钮的图片
    /// - parameter backImageName: 按钮的背景图片
    ///
    /// - returns: 返回but
    convenience init(imageName: String, backImageName: String?) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        
        if let backImgName = backImageName {
            setBackgroundImage(UIImage(named: backImgName), forState: .Normal)
            setBackgroundImage(UIImage(named: backImgName + "_highlighted"), forState: .Highlighted)
        }
        
        sizeToFit()
    }
    
    /// 便利构造函数
    ///
    /// - parameter tittle:        文字
    /// - parameter backImageName: 背景图片
    /// - parameter fontsize:      字体大小
    /// - parameter fontcolcr:     字体颜色
    ///
    /// - returns: 返回but
    convenience init(tittle: String , backImageName: String? ,fontsize: CGFloat , fontcolcr:UIColor){
        self.init()
        
        setTitle(tittle, forState: UIControlState.Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontsize)
        
        setTitleColor(fontcolcr, forState: UIControlState.Normal)
        
        if let backImageName = backImageName{
          setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        }
        sizeToFit()
    }
    /// 便利构造函数
    ///
    /// - parameter imageName:     图片名称
    /// - parameter backImageName: 背景图片的名称
    /// - parameter title:         按钮文字
    /// - parameter fontsize:      文字大小
    /// - parameter fontColor:     文字颜色
    ///
    /// - returns: 返回按钮
    convenience init(imageName: String, backImageName: String?, title:String?, fontsize:CGFloat, fontColor:UIColor){
        
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontsize)
        
        setTitleColor(fontColor, forState: UIControlState.Normal)
        
        if let backImageName = backImageName{
            setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        }
        sizeToFit()
        
    }
    
    convenience init(imageName:String){
        self.init()
        setImage(UIImage(named: imageName), forState: .Normal)
    }
    
    convenience init(image:UIImage){
        self.init()
        setImage(image, forState: .Normal)
    }
    
}
